package com.wpx.fileSys.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JdbcUtils {
	
	//内网 
//	private static String url = "jdbc:mysql://127.0.0.1:3306/fileSys?useUnicode=true&characterEncoding=utf8";
	private static String url = "jdbc:mysql://123.207.17.158:3306/fileSys?useUnicode=true&characterEncoding=utf8";
	private static String user = "root";
	private static String password = "jhJH123!";
	private static String driver = "com.mysql.jdbc.Driver";
	
//	//外网
//	
//	private static String url = "jdbc:mysql://115.159.184.122:3306/jh_sys?useUnicode=true&characterEncoding=utf8";
//	private static String user = "jianghao";
//	private static String password = "jhJH123!";
//	private static String driver = "com.mysql.jdbc.Driver";
	
	
	/*
	private static String url = "jdbc:mysql://qdm162607130.my3w.com:3306/qdm162607130_db";
	private static String user = "qdm162607130";
	private static String password = "jianghao";
	private static String driver = "com.mysql.jdbc.Driver";
	*/
	static {
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		try {
			return DriverManager.getConnection(url, user, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void close(ResultSet rs, PreparedStatement pst,
			Connection conn) {
		try {
			if (rs!=null) {
				rs.close();
				rs=null;
			}	
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			
				try {
					if (pst != null) {
						pst.close();
						pst=null;
					}
				} catch (Exception e2) {
					e2.printStackTrace();
				} finally {
					
						try {
							if (conn != null) {
								conn.close();
								conn=null;
							}
						} catch (Exception e3) {
							e3.printStackTrace();
						}
					
				}
			
		}
	}
}
